import { useCallback, useRef } from "@tarojs/taro";

export const testImageUrl =
  "https://yanxuan.nosdn.127.net/14918201901050274.jpg";

export const smallTestImageUrl =
  "http://yanxuan.nosdn.127.net/cf40c167e7054fe184d49f19121f63c7.png";

export const BASE_URL = "https://mock.ikmoons.com/mock/11/applet";

export const CONCAT_IMG_URL = (url: string) => {
  return `https://chor-young-1300991683.cos.ap-nanjing.myqcloud.com/files${url}`;
};
export const CONCAT_CDN_IMAGE_ORIGIN = (url: string) => {
  return `https://chor-young-1300991683.cos.ap-nanjing.myqcloud.com/${url}`;
};

export const REG_CDN_IMAGE_ORIGIN = (url: string) => {
  const reg = /^http.*/;
  if (reg.test(url)) {
    return url;
  } else {
    return CONCAT_CDN_IMAGE_ORIGIN(url);
  }
};

export const REG_CDN_FILE_ORIGIN = (url: string) => {
  const reg = /^http.*/;
  if (reg.test(url)) {
    return url;
  } else {
    return CONCAT_IMG_URL(url);
  }
};

export const REG_CDN_VIDEO_ORIGIN = (url: string) => {
  const reg = /^http.*/;
  if (reg.test(url)) {
    return url;
  } else {
    return CONCAT_IMG_URL(url);
  }
};



export const NoRecordPic = REG_CDN_IMAGE_ORIGIN(
  "/assets/images/page/project/mall/no-record.png"
);

export const liveId = "wx2b03c6e691cd7370";

export const useRefCallback = <T extends (...args: any[]) => any>(
  callback: T
) => {
  // const ref = useRef(callback);
  // ref.current = callback;

  // return useCallback((...args: []) => ref.current(...args), []) as T;

  const ref = useRef(callback);
  ref.current = callback;

  return useCallback((...args: []) => {
    // console.log(...args);
    return ref.current(...args);
  }, []) as T;
};

export function useRefCallback2<T extends (...args: any[]) => any>(
  callback: T
) {
  const callbackRef = useRef(callback);
  callbackRef.current = callback;

  return useCallback((...args: any[]) => callbackRef.current(...args), []) as T;
}

